package com.ljy.tkmodel.config;

import com.ljy.tkmodel.job.RoomJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RoomQuartzConfig {

    @Bean
    public JobDetail printTimeJobDetail() {
        return JobBuilder.newJob(RoomJob.class)
                .usingJobData("j1", "jv1")
                .storeDurably()
                .withIdentity("myjob", "mygroup").build();
    }

    @Bean
    public Trigger printTimeJobTrigger() {
        //CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/1 * * * * ?");
        return TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .usingJobData("t1", "tv1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3)
                        .repeatForever()).build();
    }
    @Bean
    public Scheduler roomScheduler() throws SchedulerException {
       Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(printTimeJobDetail(),printTimeJobTrigger());
        return scheduler;
    }
}
